#include "S_4_Environment_doGet.h"
#include "mi_iid_define.h"
#include "property_decoder.h"
#include "section_define.h"
#include "main.h"

extern uint8_t  g_uNo1RegList[PBS_NO1REGSIZE];
/**
 * 格式: property_value_new_float(浮点数)　
 * 取值: 最小值: -50.0, 最大值: 150.0, 步长: 0.1
 */
static void P_4_7_Temperature_doGet(property_operation_t *o)
{
	InDoorBusReg RegSection1 = {0};
	static uint16_t Temp1 = 0;
	static float Temp2 = 0.0;
#if 	PROPERTY_TYPE
	RegSection1.V8 = GetPbsRegValue(0x0010);
//	if(RegSection1.BIT1.bit7)
	{
		Temp1 = ((g_uNo1RegList[0x10]<<8)|(g_uNo1RegList[0x0F]))&0x7FFF;
		Temp2 = (float)(Temp1-1000)/10.0;
		property_value_new_float(&o->value,Temp2);
	}
	
#else	
    o->value.format = PROPERTY_FORMAT_NUMBER;
	o->value.data.number.type = DATA_NUMBER_FLOAT;
	o->value.data.number.value.floatValue = 64.0; // TODO: 这里需要读到属性真正的值
#endif	
	
}

/**
 * 格式: property_value_new_integer(整数)　
 * 取值: 最小值: 0, 最大值: 100, 步长: 1
 */
static void P_4_9_RelativeHumidity_doGet(property_operation_t *o)
{
	InDoorBusReg RegSection1 = {0};
#if 	PROPERTY_TYPE
	RegSection1.V8 = GetPbsRegValue(0x0014);
//	if(RegSection1.BIT1.bit7)
	{
		property_value_new_integer(&o->value,RegSection1.BIT1.bit0_6);
	}
#else	
    o->value.format = PROPERTY_FORMAT_NUMBER;
	o->value.data.number.type = DATA_NUMBER_INTEGER;
	o->value.data.number.value.integerValue = 16; // TODO: 这里需要读到属性真正的值
#endif
	
}

void S_4_Environment_doGet(property_operation_t *o)
{
    switch (o->piid)
    {
        case PIID_4_7_Temperature:
            P_4_7_Temperature_doGet(o);
            break;

        case PIID_4_9_RelativeHumidity:
            P_4_9_RelativeHumidity_doGet(o);
            break;

        default:
            o->code = OPERATION_ERROR_VALUE;
            break;
    }
}
